<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>
<label class="layui-form-label">标题</label>
<div class="layui-input-block">
    <input id="headline" type="text" name="headline" required lay-verify="required" placeholder="请输入标题"
           autocomplete="off"
           class="layui-input">
</div>
<label class="layui-form-label">类别</label>
<div class="layui-input-block">
    <input id="articleClass" type="text" name="articleClass" required lay-verify="required" placeholder="请输入类别"
           autocomplete="off"
           class="layui-input">
</div>
<textarea id="demo" style="display: none;"></textarea>
<button id="getBtn" class="layui-btn">提取内容</button>
<script th:src="@{/layui/layui.js}"></script>
<script>
    layui.use('layedit', function () {
        var layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/uploadArticleImg', //接口url
                type: 'post',// 默认post
            }
        });
        var index = layedit.build('demo'); //建立编辑器
        var $ = layui.jquery;
        $("#getBtn").on('click', function () {
            var articleContent = layedit.getContent(index);
            console.log(articleContent);
            $.ajax({
                url: '/addArticle',
                type: "post",
                data: {
                    content: articleContent,
                    headline: $("#headline").val(),
                    articleClass: $("#articleClass").val()
                }, success: function (res) {
                    layer.msg(res.data);
                }
            })
        });
    });
</script>
</body>
</html>